// page/member/collection.js
Page({
    data: {
        isHide: 0,
        hasList: false,          // 列表是否有数据
        productItems: []
    },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var app = getApp()
    var that = this;
    var uid = wx.getStorageSync('uid');
    wx.request({
      url: app.globalData.host + '&g=App&m=Member&a=collection', //仅为示例，并非真实的接口地址
      data: {
        uid: uid
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        that.setData({
          productItems: res.data.d,
          hasList: res.data.d ? true : false,
          isHide: true
        })
      }
    })



      // this.setData({
      //     isHide: 1,
      //     hasList: true,
      //     productItems: [
      //         {
      //             "id": "0",
      //             "imgUrl": "/images/index8.jpg",
      //             "title": "1戴安娜玫瑰11枝红色康乃馨 11支，红色石竹梅4枝",
      //             "price": "338.00",
      //             "numPeople": "1517",
      //             "selected": false
      //         },
      //         {
      //             "id": "1",
      //             "imgUrl": "/images/index9.jpg",
      //             "title": "2戴安娜玫瑰11枝红色康乃馨 11支，红色石竹梅4枝",
      //             "price": "338.00",
      //             "numPeople": "1517",
      //             "selected": false
      //         },
      //         {
      //             "id": "2",
      //             "imgUrl": "/images/index8.jpg",
      //             "title": "3戴安娜玫瑰11枝红色康乃馨 11支，红色石竹梅4枝",
      //             "price": "338.00",
      //             "numPeople": "1517",
      //             "selected": false
      //         },
      //         {
      //             "id": "3",
      //             "imgUrl": "/images/index9.jpg",
      //             "title": "4戴安娜玫瑰11枝红色康乃馨 11支，红色石竹梅4枝",
      //             "price": "338.00",
      //             "numPeople": "1517",
      //             "selected": false
      //         }
      //     ]
      // })  
  },

  /**
   * 当前选中事件
   */
  selectList(e) {
      const index = e.currentTarget.dataset.index;
      let productItems = this.data.productItems;
      const selected = productItems[index].selected;
      productItems[index].selected = !selected;
      this.setData({
          productItems: productItems
      });
  }, 
  delc:function(){
    var that = this
    var arr = that.data.productItems
    var toastStr = '';
    // 遍历取出已勾选的cid
    for (var i = 0; i < arr.length; i++) {
      if (arr[i].selected) {
        toastStr += arr[i].id;
        toastStr += ' ';
       
      }
    }
    if (toastStr){
      var app = getApp()
      var that = this;
      var uid = wx.getStorageSync('uid');
        wx.request({
          url: app.globalData.host + '&g=App&m=Member&a=delc', //仅为示例，并非真实的接口地址
          data: { aid: toastStr, uid: uid},
          header: {
            'content-type': 'application/json'
          },
          success: function (res) {
            that.setData({
              productItems: res.data.d,
              hasList: res.data.d ? true :false
            })
            wx.showToast({
              title: '删除成功',
              icon: 'success',
              duration: 2000
            })
          }
        });
    }else{
      wx.showToast({
        title: '没有选中任何商品',
        icon: 'success',
        duration: 2000
      })
    }
   
  

  },
  tz:function (){
    wx.switchTab({
      url: '/page/category/category'
    })
  }
})